package com.primary.common;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.csvreader.CsvReader;

public class CsvUtils {
	public static List<List<String>> readCsvByCsvReaderWithHeader(String filePath) {
        List<List<String>> arrList = new ArrayList<List<String>>();
        try {
            CsvReader reader = new CsvReader(filePath, ',', Charset.forName("UTF-8"));
            while (reader.readRecord()) {
                arrList.add(Arrays.asList(reader.getValues())); // 按行读取，并把每一行的数据添加到list集合
            }
            reader.close();
            System.out.println("读取的行数：" + arrList.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arrList;
    }
	
	public static List<List<String>> readCsvByCsvReaderWithoutHeader(String filePath) {
        List<List<String>> arrList = new ArrayList<List<String>>();
        try {
            CsvReader reader = new CsvReader(filePath, ',', Charset.forName("UTF-8"));
            while (reader.readRecord()) {
                arrList.add(Arrays.asList(reader.getValues())); // 按行读取，并把每一行的数据添加到list集合
            }
            reader.close();
            System.out.println("读取的行数：" + arrList.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arrList;
    }
}
